/**
 * 
 */
package com.asset.salesforce.controller.ajax;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.asset.salesforce.domain.Employee;
import com.asset.salesforce.dto.table.EmployeeListDTO;
import com.asset.salesforce.dto.table.ReadOperationParams;
import com.asset.salesforce.dto.table.ReadOperationResults;
import com.asset.salesforce.service.EmployeeService;

// TODO: Auto-generated Javadoc
/**
 * The Class SearchController.
 *
 * @author Hisham
 */
@Controller
public class SearchController {
	
	/** The employee service. */
	@Autowired
	private EmployeeService employeeService;

	/**
	 * List.
	 *
	 * @param params the params
	 * @param session the session
	 * @return the read operation results
	 */
	@RequestMapping(value = "/companyEmployeesList", method = RequestMethod.GET, produces = "application/json")
	public @ResponseBody
	ReadOperationResults list(ReadOperationParams params,HttpSession session) {
		ReadOperationResults result = new ReadOperationResults();
		Employee userDetails = (Employee) session.getAttribute("userDetails");
		List<Employee> employees = employeeService.getAllCompanyEmployess(userDetails.getCompany().getCompanyName(),params.getiDisplayStart(), params.getiDisplayLength());
		Integer size = employeeService.getAllSizeForComapnyEmployees(userDetails.getCompany().getCompanyName());
		result.setiTotalDisplayRecords(size);
        result.setiTotalRecords(size);
        result.setsEcho(params.getsEcho());
        
        List<EmployeeListDTO>employeeList = new ArrayList<EmployeeListDTO>();
		for (Employee employee : employees) {
			EmployeeListDTO data = new EmployeeListDTO();
			data.setId(employee.getId().toString());
			data.setfName(employee.getfName()+" "+employee.getlName());
			employeeList.add(data);
		}
        result.setAaData(employeeList);
        return result;
	}
}
